<form class="layui-form layui-form-pane" method="post" action="" enctype="multipart/form-data" >
    @csrf
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-inline" style="width:30%;">
            <input type="radio" name="type" value="1"  lay-filter="type" title="手机号" checked="">
            <input type="radio" name="type" value="2"  lay-filter="type" title="微信号">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号/微信号</label>
        <div class="layui-input-inline" style="width:30%;">
            <input type="type" name="phone" value='' required lay-verify="required" placeholder='请输入手机号/微信号' autocomplete="off" class="layui-input" >
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item" style="display:none;" id="qrcode">
        <label class="layui-form-label">二维码</label>
        <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
        <input type="hidden" name="qrcode" id="picname">
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        //绑定单选
        form.on('radio(type)', function (data) {
            if(data.value == 1){
                $("#qrcode").css('display','none');
            }else{
                $("#qrcode").css('display','block');
            }
        });

        layui.use('upload',function(){
            var $ = layui.jquery
                ,upload = layui.upload;
            //指定允许上传的文件类型
            upload.render({
                elem: '#test3'
                ,url: '/admin/qrcode_up' //改成您自己的上传接口
                ,accept: 'file' //普通文件
                ,done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 1){
                        $("#test3").text('上传成功!');
                        $("#picname").val(res.info);
                    }
                }
            });
        });


        //绑定提交
        form.on('submit(formDemo)', function(data){
            layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                ajax("{{url('admin/asd/insert')}}",data.field,function(data){
                    layer.close();
                    layer.closeAll();
                    layer.msg(data.msg);
                    if(data.code == 1){
                        location.href = location.href;
                    }
                });
            });
            return false;
        });
    });
</script>
